#include "qtvtkbodyproperties.h"

qtvtkbodyproperties::qtvtkbodyproperties(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);

	// Initialize vtkSceneManager
	vtkSceneManager = vtkMethods::vtkScene();

	// Add renderWindow to qvtkWidget 
	ui.qvtkWidget->GetRenderWindow()->AddRenderer(vtkSceneManager.renderer);

	// Render
	ui.qvtkWidget->GetRenderWindow()->Render();
}

qtvtkbodyproperties::~qtvtkbodyproperties()
{

}

void qtvtkbodyproperties::slot_pushButton_clicked(void)
{
	reject();
}

void qtvtkbodyproperties::slot_pushButton_2_clicked(void)
{
	accept();
}

void qtvtkbodyproperties::slot_toolButton_clicked(void)
{
	// Define a static QFileDialog
	//QFileDialog dialog(this);

	QString qfileName = QFileDialog::getOpenFileName(this, tr("Import .stl geometry file."), "", tr("STL Files (*.STL *.stl)"));

	// Open file input dialog
	//if (dialog.exec())
	if (!qfileName.isEmpty())
	{
		// Get selected file name
		//QString qfileName = dialog.getOpenFileName(this, tr("Import .stl geometry file."), "", tr("STL Files (*.STL *.stl)"));

		// Get file info
		QFileInfo fileInfo(qfileName);

		// Convert QString to std::string
		std::string stdfileName = qfileName.toStdString();

		// Add actor to scene
		vtkSceneManager.addSTLActor(fileInfo.fileName().toStdString().c_str(), stdfileName);

		// Reset camera
		vtkSceneManager.renderer->ResetCamera();

		// Update text
		ui.lineEdit->setText(qfileName);
	}
}